

# 获取浏览器驱动对象
from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service('D:/ChromeDriver/chromedriver.exe')
driver = webdriver.Chrome(service= service)
# 打开网址
driver.get("http://localhost:90/")
# 最大化
driver.maximize_window()
# 隐式等待
driver.implicitly_wait(10)
# 输入用户名
username_el = driver.find_element(By.CSS_SELECTOR,"input[placeholder='Username']")
username_el.clear()
username_el.send_keys("fhj")
sleep(1)
# 输入密码
password_el = driver.find_element(By.CSS_SELECTOR, "input[placeholder='Password']")
password_el.clear()
password_el.send_keys("123456")
sleep(1)
# 点击登录
login_btn = driver.find_element(By.CSS_SELECTOR,".el-button.el-button--primary")
login_btn.click()
sleep(1)

# 员工添加业务
# 点击系统信息管理
system_manager_link = driver.find_element(By.XPATH,"//span[contains(text(),'系统信息管理')]")
system_manager_link.click()
# 点击员工管理
sleep(1)
emp_manager_link = driver.find_element(By.XPATH,"//span[contains(text(),'员工管理')]")
emp_manager_link.click()

sleep(2)
# # 点击添加员工按钮
# emp_add_btn = driver.find_element(By.XPATH,"//span[contains(text(),'+ 新增员工')]")
# emp_add_btn.click()
# sleep(1)
#
# # 输入用户名
# username_add = driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div/div[2]/div/div[2]/form/div[1]/div/div/input")
# username_add.clear()
# username_add.send_keys("fhd")
# sleep(1)
# # 输入员工姓名
# name_add = driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div/div[2]/div/div[2]/form/div[2]/div/div/input")
# name_add.clear()
# name_add.send_keys("冯海东")
# # # 性别选择
# # gender_link = driver.find_element(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(3) > div > div > div > input")
# # gender_link.click()
# # # 选择男
# # sleep(1)
# # nan_choose = driver.find_element(By.XPATH,"/html[1]/body[1]/div[5]/div[1]/div[1]/ul[1]/li[1]/span[1]")
# # nan_choose.click()
#
# # 点击取消按钮
# cancel_btn = driver.find_element(By.XPATH,"//span[contains(text(),'取消')]")
# cancel_btn.click()
#
#
# # 输入员工姓名
# name_input = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入员工姓名']")
# name_input.clear()
# name_input.send_keys("冯海杰")
# # 点击查询按钮
# query_btn = driver.find_element(By.XPATH,"//span[contains(text(),'查询')]")
# query_btn.click()

# 部门管理业务
# 点击部门管理
dept_manager_link = driver.find_element(By.XPATH,"//span[contains(text(),'部门管理')]")
dept_manager_link.click()

# 点击添加部门按钮
dept_add_btn = driver.find_element(By.XPATH,"//span[contains(text(),'+ 新增部门')]")
dept_add_btn.click()
sleep(1)
# 输入新增部门的名字
dept_input = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入部门名称']")
dept_input.clear()
dept_input.send_keys("教师部")
# 点击确认键
dept_add_ok_btn = driver.find_element(By.XPATH,"//span[contains(text(),'确 定')]")
dept_add_ok_btn.click()

# 部门删除
dept_delete_btn = driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div/div[2]/div[3]/table/tbody/tr[3]/td[4]/div/button[2]/span")
dept_delete_btn.click()
# 点击确定键
dept_delete_ok_btn = driver.find_element(By.XPATH,"//span[contains(text(),'确定')]")
dept_delete_ok_btn.click()

sleep(1)
# 关闭驱动
driver.quit()
